//
//  MainViewController.swift
//  WeiBo
//
//  Created by Xmen on 16/9/19.
//  Copyright © 2016年 111. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

//        self.view.backgroundColor = UIColor.blue
        
        let wqTabBar = WQTabBar()
        wqTabBar.wqdelegate? = self as! WQTabBarDelegate
        wqTabBar.compaseButtonClosure = { [weak self] in
                print("bibao")
//            let aouthvc = WQOAuthViewController()
//            self?.navigationController?.present(aouthvc, animated: true, completion: nil)
        }
        setValue(wqTabBar, forKey: "tabBar")
        

        addChildViewController(childController: HomeViewController(), title: "主页",imageName: "tabbar_home")
        addChildViewController(childController: MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: DiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: ProfileViewController(), title: "我的", imageName: "tabbar_profile")
        
        
    }

    func addChildViewController(childController: UIViewController, title: String, imageName: String){
        
        // 设置tabbar图片及渲染模式
        childController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        // 设置tabbar文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 13)], for: .normal)
        // 设置tabbar文字选中颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        // 设置tabbar的标题
        childController.title = title
        // 设置子控制器嵌入的navigationVC
        let nav = UINavigationController(rootViewController: childController)
        // 设置已嵌套的nav为tabbaVC的子VC
        addChildViewController(nav)
    }


}
